package com.example.doer.reading.AppAdapters;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.ab.image.AbImageLoader;
import com.example.doer.reading.AppActivities.MyHomeActivity;
import com.example.doer.reading.AppDataModel.MyMessage;
import com.example.doer.reading.R;

import java.util.List;

import de.hdodenhof.circleimageview.CircleImageView;

/**
 * Created by doer on 2017/7/10.
 */

public class MesListAdapter extends BaseAdapter {
    Context context;
    List<MyMessage> list;
    int res;

    public MesListAdapter(Context c,List<MyMessage> l,int r){
        this.context=c;
        this.list=l;
        this.res=r;
    }
    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public MyMessage getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = LayoutInflater.from(context).inflate(res,null);
        final CircleImageView imageView=(CircleImageView) view.findViewById(R.id.mes_list_image);
        TextView textView1=(TextView)view.findViewById(R.id.mes_list_title);
        TextView textView2=(TextView)view.findViewById(R.id.mes_list_content);
        TextView textView3=(TextView)view.findViewById(R.id.mes_list_info);
        ImageView actionImage=(ImageView)view.findViewById(R.id.actionView);

        TextView textView4= (TextView) view.findViewById(R.id.top);
        TextView textView5= (TextView) view.findViewById(R.id.bottom);
        textView4.setText("            ");
        textView5.setText("            ");

        final MyMessage m =getItem(position);
        AbImageLoader abImageLoader=AbImageLoader.getInstance(context);
        String url="http://192.168.191.1/Reading/ImageDoServlet?Action=download&Category=UserLogo&ImageName="+m.getUserID();
        abImageLoader.display(imageView,url,360,360);
        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(context, MyHomeActivity.class);
                intent.putExtra("UserID",m.getUserID());
                context.startActivity(intent);
            }
        });
        actionImage.setImageResource(m.getResID());
        textView1.setText(m.getTitle());
        textView2.setText(m.getContent());
        textView3.setText(m.getInfo());
        return view;
    }
}
